package com.tyk.bookstore.back.product.service.impl;


import com.tyk.bookstore.back.common.core.util.AssertUtil;
import com.tyk.bookstore.back.common.core.util.FileUtil;
import com.tyk.bookstore.back.common.dal.mapper.dto.SinDto;
import com.tyk.bookstore.back.product.model.dto.Book4CommentDto;
import com.tyk.bookstore.back.product.model.dto.Book4StockDto;
import com.tyk.bookstore.back.product.model.dto.BookDto;
import com.tyk.bookstore.back.product.model.entity.BookDo;
import com.tyk.bookstore.back.product.model.result.BookResultEnum;
import com.tyk.bookstore.back.product.repository.BookRepository;
import com.tyk.bookstore.back.product.service.BookApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author tyk
 * @description 书籍对内暴露接口
 */
@Service
@RequiredArgsConstructor
public class BookApiServiceImpl implements BookApiService {

    private final BookRepository bookRepository;


    @Override
    public void assertExistById(Long id) {
        AssertUtil.isTrue(
                bookRepository.exist1Eq(
                        BookDo::getId, id, BookDo.class
                ),
                BookResultEnum.BOOK_NOT_FOUND
        );
    }

    @Override
    public Book4StockDto getBook4StockDtoById(Long id) {
        Book4StockDto dto = bookRepository.selectBook4StockDtoById(id);
        AssertUtil.notNull(dto, BookResultEnum.BOOK_NOT_FOUND);
        return dto;
    }

    @Override
    public List<Book4StockDto> getBook4StockDtoListByIdSet(Set<Long> idSet) {
        if (idSet.isEmpty()) return new ArrayList<>();
        return bookRepository.selectBook4StockDtoListByIdSet(idSet, idSet.size());
    }

    @Override
    public List<Book4CommentDto> getBook4CommentDtoListByIdSet(Set<Long> idSet) {
        if (idSet.isEmpty()) return new ArrayList<>();
        return bookRepository.selectBook4CommentDtoListByIdSet(idSet, idSet.size());
    }


}
